<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="root"></div>
<script src="../../javascript/react.development.js"></script>
<script src="../../javascript/react-dom.development.js"></script>
<!--引入prop-types用于对props的类型进行限制-->
<script src="../../javascript/prop-types.js"></script>
<script src="../../javascript/babel.min.js"></script>

<script type="text/babel">
    class Person extends React.Component {
        static propTypes = {
            name: PropTypes.string.isRequired,
            age: PropTypes.number.isRequired,
            getAge: PropTypes.func
        }
        static defaultProps = {
            sex: "男"
        }
        /*
        * 在React中构造函数仅仅用于以下两种情况： 1.通过给this.state赋值对象来初始化内部的state 2.为事件处理函数绑定this的指向
        * */
        constructor(props, context) {
            /*
            *在React组件挂载之前会调用组件的构造函数，在为React.Component子类实现构造函数时，应该在其它语句之前调用super(props)
            *否则this.props在构造函数中可能会出现未定义的bug
            */
            // 构造器是否接收props是否传递给super()，取决于：是否希望在构造器中通过this访问props
            super(props, context)
            console.log(this.props)
            console.log(props)
        }

        render() {
            const {name, age, sex} = this.props
            return (
                <div className="app">
                    <ul>
                        <li>姓名是：{name}</li>
                        <li>年龄是：{age}</li>
                        <li>性别是：{sex}</li>
                    </ul>
                </div>
            );
        }
    }

    ReactDOM.render(<Person name="陶品奇" age={22} sex="男"></Person>, document.querySelector("#root"))
</script>
</body>
</html>